<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<head th:include="admin/common/resource ::commonHead('首页')" ></head>
<body>
<div class="container-fluid">
    <div class="toolbar btn-group-sm" role="toolbar" >
        <h6 style="margin-top: 10px;margin-bottom: 20px" > 后台管理系统 / 影视管理 / 书籍列表 </h6>
        <div style="margin-bottom: 10px;" >
            <button shiro:hasPermission="book:add" onclick="loadPage('/admin/book/add')"  type="button" class="btn btn-sm btn-success"> 添加书籍 </button>
            <!--<button type="button" class="btn btn-sm btn-primary"> 导出 </button>-->
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th scope="col"> ID </th>
            <th scope="col"> 书名 </th>
            <th scope="col"> 缩略图 </th>
            <th scope="col"> 所属分类 </th>
            <th scope="col"> 发布人 </th>
            <th scope="col"> 付费标准 </th>
            <th scope="col"> 价格 </th>
            <th scope="col"> 创建时间 </th>
            <th scope="col"> 状态 </th>
            <th scope="col"> 操作 </th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="book:${pager.list}" >
            <th scope="row" th:text="${book.id}" ></th>
            <td th:text="${book.title}" ></td>
            <td>
                <img th:src="${imageService+book.picture}" style="height: 40px" alt="">
            </td>
            <td th:text="${book.categoryName}" >  </td>
            <td th:text="${book.authorName}"></td>
            <td th:text="${book.cost}==1?'收费':'免费'" ></td>
            <td th:text="${book.price}" ></td>
            <td th:text="${#dates.format(book.createTime,'yyyy-MM-dd HH:mm')}" ></td>
            <td>正常</td>
            <td>
                <a shiro:hasPermission="book:edit" class="btn-outline-primary" th:href="@{'/admin/book/edit?id='+${book.id}}">编辑</a>
                <a shiro:hasPermission="book:delete" class="btn-outline-danger" th:href="@{'javascript:destroy('+${book.id}+')'}">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    <!-- 分页 -->
    <div th:replace="admin/common/pager ::page_pager(${pager.currentPage},0,${pager.totalPage}, @{/admin/book/list})"></div>
</div>
</body>
<div th:include="admin/common/resource ::footerJs"></div>
<script th:src="@{/layui/layui.all.js}"></script>
<script>
    function destroy(id){
        layer.confirm('真的删除这本书吗?', function(index){
            layer.close(index);
            //向服务端发送删除指令
            $.ajax({
                type:'delete',
                url: "/admin/book/delete",
                data: {
                    id: id
                },
                success: function (data) {
                    console.log(data);
                    if(data.status == 1){
                        layer.msg("成功",function () {
                            window.location.reload();
                        },2000)
                    }else{
                        layer.msg("失败")
                    }
                }
            })
        });
    }
</script>
</html>